{include file="Public:header2"/}
<body>
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-card-body">
            <xblock>
                <div style="padding-bottom: 10px;">
                    <a class="layui-btn" onclick="advert_add()">添加轮播图</a>
                    <span style="line-height:40px;float:right;">共有数据： {$count}条</span>
                </div>
            </xblock>
            <table class="layui-table">
                <thead>
                <tr>
                    <th>类型</th>
                    <th>图片</th>
                    <th>标题</th>
                    <th>排序值</th>
                    <th>操作</th>
                </tr>
                </thead>
                <tbody>
                {volist name="data" id="vo"}
                <tr>
                    <td>
                        {if $vo['type'] eq 1}
                        <button class="layui-btn layui-btn-info layui-btn-radius layui-btn-sm">首页</button>
                        {elseif $vo['type'] eq 3}
                        <button class="layui-btn layui-btn-warm layui-btn-radius layui-btn-sm">商城</button>
                        {/if}
                    </td>
                    <td><img src="{PHP} echo imageUrl($vo['imgurl']){/php}" style="height:60px;"></td>
                    <td>{$vo['title']}</td>
                    <td>{$vo['sort']}</td>
                    <td >
                        <a style="text-decoration:none" title="编辑" onclick="advert_edit({$vo.id})" class="layui-btn layui-btn-normal layui-btn-xs">
                            <i class="layui-icon layui-icon-edit"></i>编辑
                        </a>
                        <a style="text-decoration:none" title="删除" onClick="del({$vo.id},2)" class="layui-btn layui-btn-xs layui-btn-danger">
                            <i class="layui-icon"></i>删除
                        </a>
                    </td>
                </tr>
                {/volist}
                {if condition="$count eq 0"}
                    <tr><td colspan='3' style="text-align:center;">暂时没有数据！</td></tr>
                {/if}
                </tbody>
            </table>
            <div class="my_page layui-box layui-laypage layui-laypage-default">
                {$page|raw}
            </div>
        </div>
    </div>
</div>
{include file="Public:footer"/}
<script type="text/javascript">
    layui.use(['table'], function(){

    });


    //添加轮播图
    function advert_add() {
        var url  = "{:url('/admin/advert_add')}";
        layer.open({
            type: 2,
            title: '添加轮播图',
            shadeClose: false,
            shade: 0.3,
            area: ['50%', '80%'],
            content: url,
        });
    }

    //编辑轮播图
    function advert_edit(id) {
        var url  = "{:url('/admin/advert_edit?id="+id+"')}";
        layer.open({
            type: 2,
            title: '编辑轮播图',
            shadeClose: false,
            shade: 0.3,
            area: ['50%', '80%'],
            content: url,
        });
    }

    //上下架、删除
    function del(id,type){
        layer.confirm('确认要删除吗？',function(){
            var url = "{:url('/admin/advert_del')}";
            var load=layer.load(2);
            var $ = layui.$;
            $.post(url,{"id":id,'type':type},function(data){
                if(data.status == 1){
                    layer.msg(data.msg,{icon:1,time:1000},function(){
                        location.reload();
                    });
                }else{
                    layer.msg(data.msg,{icon:2,anim:6,time:1500},function(){
                        layer.close(load);
                    });
                }
            })
        });
    }
</script>
</body>
</html>


